/**
 * <pre>
 * Copyright 2008 openmaximo.net
 * 
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an &quot;AS IS&quot; BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 * </pre>
 */
package net.openmaximo.maximo.app.excelconfig;

import java.rmi.RemoteException;

import net.openmaximo.log.Log4jLogger;

import psdi.mbo.Mbo;
import psdi.mbo.MboSet;
import psdi.mbo.MboValue;
import psdi.util.MXException;

/**
 * <p>
 * ExcelConfig MBO
 * </p>
 * 
 * @author openmaximo.net
 * 
 */
public class ExcelConfig extends Mbo implements ExcelConfigRemote {
  private static final Class iClass = ExcelConfig.class;
  /**
   * 
   */
  private static final long serialVersionUID = -6445150976420213790L;

  /**
   * 
   * @param mboSet
   * @throws MXException
   * @throws RemoteException
   */
  public ExcelConfig(MboSet mboSet) throws MXException, RemoteException {
    super(mboSet);
  }

  /**
   * <p>
   * When adding manage the readonly fields my own way.
   * </p>
   * 
   * @see psdi.mbo.Mbo#add()
   */
  public void add() throws MXException, RemoteException {
    Log4jLogger.info(iClass, ".add() started...");
    super.add();
    Mbo ownerMbo = (Mbo) this.getOwner();
    if (ownerMbo != null) {
      String grpName = ownerMbo.getString("groupname");
      this.setValue("groupname", grpName);
    }
    MboValue objectnameMboValue = this.getMboValue("objectname");
    MboValue attributenameMboValue = this.getMboValue("attributename");
    if ((attributenameMboValue != null) && (objectnameMboValue != null)) {
      if (objectnameMboValue.isNull()) {
        attributenameMboValue.setReadOnly(true);
      } else {
        attributenameMboValue.setReadOnly(false);
      }
    }
    Log4jLogger.info(iClass, ".add() finished.");
  }

  /**
   * 
   * @see psdi.mbo.Mbo#init()
   */
  public void init() throws MXException {
    Log4jLogger.info(iClass, ".init() started...");
    super.init();
    MboValue objectnameMboValue = this.getMboValue("objectname");
    MboValue attributenameMboValue = this.getMboValue("attributename");
    if ((attributenameMboValue != null) && (objectnameMboValue != null)) {
      if (objectnameMboValue.isNull()) {
        attributenameMboValue.setReadOnly(true);
      } else {
        attributenameMboValue.setReadOnly(false);
      }
    }
    Log4jLogger.info(iClass, ".init() finished.");
  }

}
